#include "Halton.h"
#include <stdlib.h>

Halton::Halton(void)
{
}

Halton::Halton( int base )
{
	invBase = 1.0 / base;
	value = rand();
}
Halton::~Halton(void)
{
}

void Halton::reset()
{
	value = rand();
}

double Halton::getNext()
{
	double r = 1.0 - value - 1e-10;
	if (invBase < r)
		value += invBase;
	else {
		double hh, h = invBase;
		do {
			hh = h;
			h *= invBase;
		} while (h >= r);
		value += hh + h - 1.0;
	}
	return value;
}